package com.wayhome.springfarmework.context.support;

import com.wayhome.springfarmework.beans.BeansException;
import com.wayhome.springfarmework.beans.factory.support.DefaultListableBeanFactory;

import java.io.IOException;

public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {

    private DefaultListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() throws BeansException, IOException {
        DefaultListableBeanFactory beanFactory = createBeanFactory();
        loadBeanDefinitions(beanFactory);
        this.beanFactory = beanFactory;
    }

    private DefaultListableBeanFactory createBeanFactory(){
        return new DefaultListableBeanFactory();
    }

    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory factory) throws IOException;

    @Override
    public DefaultListableBeanFactory getBeanFactory() {
        return this.beanFactory;
    }
}
